package com.innve.scd.ecd;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.util.List;

/**
 * Created by wlc on 2017/4/13.
 */
@RestController
public class ClientController {
    final String SERVICE_NAME = "eureka-service-demo";

    @Autowired
    DiscoveryClient client;

    @RequestMapping("/")
    public String getAll() {
        List<ServiceInstance> instances = client.getInstances(SERVICE_NAME);
        URI uri = null;
        if (instances != null && instances.size() > 0) {
            uri = instances.get(0).getUri();
        }

        String a = new RestTemplate().getForObject(uri + "/word/a", String.class);
        String b = new RestTemplate().getForObject(uri + "/word/b", String.class);
        return a + b;
    }
}
